package wah;

import static org.junit.Assert.assertTrue;
import wah.test.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;

/**
 * Tests that WahibRobot aiming its gun to the body of Corners robot.
 * @author Wahib Hanani
 *
 */
public class TestWahibRobotTargetting extends RobotTestBed {
  /** True if the robot aiming to the body of Corners robot. */
  boolean targetting = false;
  
  /**
   * Specifies that Corners and WahibRobot are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Corners,wah.WahibRobot";
  }
  
  /**
   * This test runs for 1 round.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
  
  /**
   * After each turn, check to see if WahibRobot aiming its gun to the body of Corners robot.
   *  If so, set the corresponding flag.
   * @param event Info about the current state of the battle.
   */
  @Override 
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    IRobotSnapshot enemy = event.getTurnSnapshot().getRobots()[0];
    double rgHeading = robot.getGunHeading(); 
    double ebHeading = enemy.getBodyHeading();

    if (rgHeading == ebHeading) {
      targetting = true;
    }
  
  }  
  /**
   * After the battle, check to see that we've aiming to the body of enemy. 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check if WahibRobot aiming to the target", targetting);
     
  }

}
